<?php 
class Admin_ManagerController extends Zend_Controller_Action{
	public function init(){
        $layoutPath = APP_PATH . '\templates\admin\\';
        
        $option = array ('layout'     => 'index',
                         'layoutPath' => $layoutPath,
                         'contentKey' => 'content' );
        Zend_Layout::startMvc( $option );
    }
	
	public function indexAction(){
	   
		$adm = new Admin_Model_Admins();
		$arradm = $adm->getAllAdmin();             
		$this->view->data = $arradm;
		
	}
	
	/*
	* @auth: vuhai4187
	* @date: 06.11.2011
	* @return
	*/
	public function addAction(){
	   $adm = new Admin_Model_Admins();
		if($this->_request->isPost()){ 
		     $username = $this->_request->getParam('txtUsrName');
             
             $password = $this->_request->getParam('txtUsrPwd');
             
             $fullname = $this->_request->getParam('txtFullName');
             
             $email = $this->_request->getParam('txtEmail');
             
             $err='';
             $i=1;
             
             if($username==''){
                $err.=$i.' UserName be not null.</br>';
                $i++;
             }else{
                $return['username']=$username;
             }
             
             if($password==''){
                $err.=$i.' Password be not null.</br>';
                $i++;
             }else{
                $return['password']=$password;
             }
             
             if($fullname==''){
                $err.=$i.' FullName be not null.</br>';
                $i++;
             }else{
                $return['fullname']=$fullname;
             }
             
             if($email==''){
                $err.=$i.' Email be not null.';
                $i++;
             }else{
                $return['email']=$email;
             }
             if($err!=''){
                $this->view->err = $err;
                $this->view->return = $return;
             }else{
                $check = $adm->addAdmin($username,$password,$fullname,$email);
                if($check){
                    $this->_redirect('/admin/index');
                }
             }
             
		}
	}
	
	/*
	* @auth: vuhai4187
	* @date: 06.11.2011
	* @return
	*/
	public function editAction(){
	    $adm = new Admin_Model_Admins();
        $id = $this->_request->getParam('id');
        $username = $this->_request->getParam('txtUsrName');             
        $password = $this->_request->getParam('txtUsrPwd');             
        $fullname = $this->_request->getParam('txtFullName');             
        $email    = $this->_request->getParam('txtEmail');
      
		if($this->_request->isPost()){ 
		     
             
             $err='';
             $i=1;
             
             if($username==''){
                $err.=$i.' UserName be not null.</br>';
                $return['adm_usrname']='';
                $i++;
             }else{
                $return['adm_usrname']=$username;
             }
             
             if($password==''){
                $err.=$i.' Password be not null.</br>';
                $return['adm_usrpwd']='';
                $i++;
             }else{
                $return['adm_usrpwd']=$password;
             }
             
             if($fullname==''){
                $err.=$i.' FullName be not null.</br>';
                $return['adm_fullname']= '';
                $i++;
             }else{
                $return['adm_fullname']=$fullname;
             }
             
             if($email==''){
                $err.=$i.' Email be not null.';
                $return['adm_email']='';
                $i++;
             }else{
                $return['adm_email']=$email;
             }
             
             if($err!=''){
                $this->view->err = $err;
                $this->view->lsadm = $return;
             }else{
                $check = $adm->editAdmin($username,$password,$fullname,$email,$id);
                if($check){
                    $this->_redirect('/admin/manager/index');
                }
             }
             
		}else{
		      $this->view->lsadm = $adm->getAdmin($id);
		}
	
	}
	
	/*
	* @auth: vuhai4187
	* @date: 06.11.2011
	* @return
	*/
	public function deleteAction(){
		$adm = new Admin_Model_Admins();
        $id = $this->_request->getParam('id');
		$check = $adm ->delete('adm_id IN('.$id.')');
		if($check){
			$this->_redirect('/admin/manager/index');
		}
	}
}